package org.mifos.boss.ui.controller;

import java.io.IOException;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.mifos.boss.application.model.UserCredentials;
import org.mifos.boss.domainmodel.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


@Controller
public class LoginController extends AbstractController {

	static Logger logger = Logger.getLogger(LoginController.class);
	


    /**
     * Adds a new customer by delegating the processing to CustomerServiceImpl.
     * Displays a confirmation JSP page
     * 
     * @return  the name of the JSP page
     */
   @RequestMapping(value = "/login")
    public String login(Model model) {
		
    	logger.debug("Received request to login");
        model.addAttribute("user", new User());
        
        return "BossLogin";
        }

   @RequestMapping(value = "/validateUser")
	public String validateUser(@ModelAttribute("UserCredentials") UserCredentials user , HttpSession session) {
	   user.getJ_username();//check if the values are coming... i checked and the values are coming to this point.
	   user.getJ_username();
	   ModelAndView model = new ModelAndView();
	   //code where we check the DB for user credentials
		logger.debug("Received request to login");
		model.addObject("user", new User());
		
		session.setAttribute("currentUser", user);
		
		//go to DB and validate user
		//customerBusiness.validateUser(user);in business validate this
		
		//if its a valid user
		
		
		return "bossDashboard";
	}

 
}
